package com.atbeijing.bigdata.spark.core.rdd.operator.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark02_Oper_Action {

    def main(args: Array[String]): Unit = {

        val conf = new SparkConf().setMaster("local[*]").setAppName("ActionOperator")
        val sc = new SparkContext(conf)

        // TODO 算子 - 行动

        // TODO reduce
        val rdd : RDD[Int] = sc.makeRDD(List(1,2,3,4),2)

        // (Int, Int) => Int
        rdd.map(_*2)
        // spark中，调用RDD对象的行动算子，会执行作业，每一次调用，都会执行不同的作业
        val i: Int = rdd.reduce(_+_)
        val ints: Array[Int] = rdd.collect()
        println(i)
        println(ints)

        sc.stop()

    }
}
